package com.example.speeddating.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.speeddating.entity.FollowTopic;
import com.example.speeddating.mapper.FollowTopicMapper;
import com.example.speeddating.service.FollowTopicService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *
 * @author tina
 * @since 2023-06-28 11:14:33
 */
@Service
public class FollowTopicServiceImpl extends ServiceImpl<FollowTopicMapper, FollowTopic> implements FollowTopicService {

    @Autowired
    private FollowTopicMapper followTopicMapper;

    @Override
    public boolean selectUserFollowTopic(long user_id, int topic_id) {//true已经添加过
        QueryWrapper<FollowTopic> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", user_id);
        queryWrapper.eq("topic_id", topic_id);
        FollowTopic followTopic = followTopicMapper.selectOne(queryWrapper);
        if (followTopic != null) {
            return true;
        }else {
            return false;
        }
    }

    @Override
    public void insertFollowTopic(long user_id, int topic_id) {
        if (!selectUserFollowTopic(user_id, topic_id)) {
            FollowTopic followTopic = new FollowTopic();
            followTopic.setUserId(user_id);
            followTopic.setTopicId(topic_id);
            followTopicMapper.insert(followTopic);
        }
    }
}
